/**
 * 
 */
package nl.sportan.samenloop;

import nl.sportan.samenloop.adapter.ImageListPageAdapter;
import nl.sportan.samenloop.communication.PhotoListTarget;
import nl.sportan.samenloop.communication.flickr.PhotoListRetriever;
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.os.Handler;
import android.support.v4.view.ViewPager;
import android.view.Window;

import com.gmail.yuyang226.flickr.photos.PhotoList;

/**
 * @author Bram Wiekens
 * 
 */
public class PhotoListActivity extends Activity implements PhotoListTarget {

	//private final static String TAG = "PhotoListView";

	private Handler handler;
	private PhotoList photoList;

	public PhotoListActivity() {
		handler = new Handler();
	}

	public void onCreate(Bundle savedInstanceState) {
		Intent i = getIntent();
		String id = i.getStringExtra("PhotosetId");

		super.onCreate(savedInstanceState);

		requestWindowFeature(Window.FEATURE_CUSTOM_TITLE);

		setContentView(R.layout.flickr_view);

		getWindow().setFeatureInt(Window.FEATURE_CUSTOM_TITLE,
				R.layout.title_bar);

		if (id != null && !id.isEmpty()) {
			Thread t = new Thread(new PhotoListRetriever(id, this));
			t.start();
		}
	}


	private class PhotosetUpdater implements Runnable {

		public void run() {
			/*PhotoAdapter img = new PhotoAdapter(PhotoListView.this,
					photoList);
			photoGrid.setAdapter(img);*/
			
			ViewPager vp = (ViewPager) findViewById(R.id.pager);
			vp.setAdapter(new ImageListPageAdapter(PhotoListActivity.this,photoList));
		}

	}

	public void setPhotoList(PhotoList photoList) {
		this.photoList = photoList;
		
		handler.post(new PhotosetUpdater());
	}

}
